package com.hrm.controller;


import com.hrm.pojo.DTO.EmployeeDTO;
import com.hrm.pojo.DTO.EmployeeVO;
import com.hrm.pojo.Employee;
import com.hrm.service.EmployeeService;
import com.hrm.utils.entity.PageResult;
import com.hrm.utils.entity.Result;
import com.hrm.utils.entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "员工相关接口")
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 员工查询
     * @param employeeDTO
     * @return
     */
    @ApiOperation("员工查询")
    @GetMapping("/page")
    public Result list(EmployeeDTO employeeDTO){
        PageResult<EmployeeVO> pageEmployeeVO = employeeService.page(employeeDTO);
        return new Result(pageEmployeeVO!=null,pageEmployeeVO!=null?StatusCode.SUCCESS:StatusCode.ERROR,"操作完成",pageEmployeeVO);
    }

    /**
     * 添加员工
     * @param employee
     * @return
     */
    @ApiOperation("添加员工")
    @PostMapping("/add")
    public Result insert(@RequestBody Employee employee){
        Boolean flag = employeeService.insert(employee);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");

    }
    /**
     * 修改员工
     */
    @ApiOperation("修改员工")
    @PutMapping("/update")
    public Result update(@RequestBody Employee employee){
        Boolean flag = employeeService.updateById(employee);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");
    }

    /**
     * 删除员工
     * @param id
     * @return
     */
    @ApiOperation("删除员工")
    @DeleteMapping("delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        Boolean flag = employeeService.deleteById(id);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");
    }
}
